package cn.com.headfree.userinfo.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.gta.edu.sdk.base.dao.impl.BaseDaoImpl;
import com.gta.edu.sdk.util.StringUtil;

import cn.com.headfree.userinfo.dao.IPrizeDao;
import cn.com.headfree.vo.PrizeVo;

@Repository("prizeDao")
public class PrizeDaoImpl extends BaseDaoImpl<PrizeVo> implements IPrizeDao {

	@Override
	public List<PrizeVo> getContestPrizes(String beginTimeStr, String endTimeStr, String erpNo) {
		StringBuilder sqlBuilder = new StringBuilder(
				"select id as item_id,award_name as award from t_contest_info where 1=1 and is_valid=0 ");
		ArrayList<Object> arrayList = new ArrayList<Object>();
		if (!StringUtil.isNullOrEmpty(beginTimeStr)) {
			sqlBuilder.append(" and award_date>=? ");
			arrayList.add(beginTimeStr);
		}
		if (!StringUtil.isNullOrEmpty(endTimeStr)) {
			sqlBuilder.append(" and award_date<=? ");
			arrayList.add(endTimeStr);
		}
		sqlBuilder.append(" and erp_no=? ");
		arrayList.add(erpNo);
		return this.findAllBySQL(PrizeVo.class, sqlBuilder.toString(), null, false,arrayList.toArray());
	}

	@Override
	public List<PrizeVo> getHonorPrizes(String beginTimeStr, String endTimeStr, String erpNo) {
		StringBuilder sqlBuilder = new StringBuilder(
				"select id as item_id,honor_title as award from t_honor_info where 1=1 and is_valid=0 ");
		ArrayList<Object> arrayList = new ArrayList<Object>();
		if (!StringUtil.isNullOrEmpty(beginTimeStr)) {
			sqlBuilder.append(" and acqu_time>=? ");
			arrayList.add(beginTimeStr);
		}
		if (!StringUtil.isNullOrEmpty(endTimeStr)) {
			sqlBuilder.append(" and acqu_time<=? ");
			arrayList.add(endTimeStr);
		}
		sqlBuilder.append(" and erp_no=? ");
		arrayList.add(erpNo);
		return this.findAllBySQL(PrizeVo.class, sqlBuilder.toString(), null, false,arrayList.toArray());
	}

	@Override
	public List<PrizeVo> getTecManInnovPrizes(String beginTimeStr, String endTimeStr, String erpNo) {
		StringBuilder sqlBuilder = new StringBuilder(
				"select a.id as item_id,award_name as award from t_tec_man_innov a inner join t_part_rank b on a.id=b.item_id where 1=1 and a.is_valid=0 ");
		ArrayList<Object> arrayList = new ArrayList<Object>();
		if (!StringUtil.isNullOrEmpty(beginTimeStr)) {
			sqlBuilder.append(" and a.award_date>=? ");
			arrayList.add(beginTimeStr);
		}
		if (!StringUtil.isNullOrEmpty(endTimeStr)) {
			sqlBuilder.append(" and a.award_date<=? ");
			arrayList.add(endTimeStr);
		}
		sqlBuilder.append(" and b.erp_no=? ");
		arrayList.add(erpNo);
		return this.findAllBySQL(PrizeVo.class, sqlBuilder.toString(), null, false,arrayList.toArray());
	}

}
